package com.springboot.frame.starter.web.exception;

import com.springboot.frame.swagger.GlobalResultEnum;

/**
 * 业务异常
 *
 * @author TaoYu
 */
public class ResultEnumException extends RuntimeException {

    private static final long serialVersionUID = -232388151980021793L;

    /**
     * 自定义异常码
     */
    private int code = GlobalResultEnum.FAIL.getCode();

    private Object data;

    public ResultEnumException() {
        super();
    }

    /**
     * 将定义的异常信息赋给异常
     *
     * @param code
     * @param msg
     */
    public ResultEnumException(int code, String msg) {
        this(code, msg,null);
    }

    public ResultEnumException(GlobalResultEnum code) {
        this(code, null);
    }

    public ResultEnumException(GlobalResultEnum code, Object o) {
        super(code.getMessage());
        this.code = code.getCode();
        this.data = o;
    }

    public ResultEnumException(int code, String msg, Object o) {
        super(msg);
        this.code = code;
        this.data = o;
    }

    public ResultEnumException(String message, Throwable cause) {
        super(message, cause);
    }

    public ResultEnumException(String message) {
        super(message);
    }

    public ResultEnumException(Throwable cause) {
        super(cause);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
